package com.pyip.user.controller;


import com.pyip.user.domain.User;
import com.pyip.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    // 调用远程服务
//    @DubboReference(version = "v1.0.0")
    @DubboReference(version = "v2.0.0",retries = 0,loadbalance = "roundrobin") // 局部配置，只影响userService
    private UserService userService;
    /**
     * * Random ：按权重随机，默认值。按权重设置随机概率。
     * * RoundRobin ：按权重轮询
     * * LeastActive：最少活跃调用数，相同活跃数的随机。
     * * ConsistentHash：一致性 Hash，相同参数的请求总是发到同一提供者。
     */

    /**
     * 路径： /user/110
     * @param id 用户id
     * @return 用户
     */
    @GetMapping("/{id}")
    public User queryById(@PathVariable("id") Long id) {
        return userService.queryById(id);
    }

    @GetMapping("/username/{id}")
    public String queryUserNameById(@PathVariable("id") Long id) {
        return userService.queryUserNameById(id);
    }
}
